package action;

/**
 * ServiceCallEditAction.java
 * Purpose: Allows the user to edit a service call
 * 
 * @author Hans Brems
 * @version 1.0 31/05/2012
 */

import java.util.List;

import persistency.CodeRepository;
import persistency.CustomerRepository;
import persistency.OperatorRepository;
import persistency.ServiceCallRepository;
import model.Code;
import model.Customer;
import model.Operator;
import model.ServiceCall;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ServiceCallEditAction extends ActionSupport {
	/* The id of the service call to edit */
	private int id;
	/* The service call to edit */
	private ServiceCall serviceCall;
	/* List of status */
	private List<Code> statusList;
	/* List of priorities */
	private List<Code> priorityList;
	/* List of customers */
	private List<Customer> customerList;
	/* List of operators */
	private List<Operator> operatorList;
	
	/** Executes an incoming request */
	public String execute() throws Exception {
		// Get status codes
		CodeRepository codeRepository = new CodeRepository();
		this.statusList = codeRepository.getByCodeTypeId(2);
		this.priorityList = codeRepository.getByCodeTypeId(1);
		
		// Get customers
		CustomerRepository customerRepository = new CustomerRepository();
		this.customerList = customerRepository.getAll();
		
		// Get operators
		OperatorRepository operatorRepository = new OperatorRepository();
		this.operatorList = operatorRepository.getAll();

		// Get service calls
		ServiceCallRepository repository = new ServiceCallRepository();
		this.serviceCall = repository.getById(this.id);
		
		return SUCCESS;
	}
	
	/** Commits a service call */
	public String commit() throws Exception {
		return INPUT;
	}
	
	/** Returns the id of the service call to edit */
	public int getId() {
		return this.id;
	}
	
	/** Sets the id of the service call to edit */
	public void setId(int id) {
		this.id = id;
	}
	
	/** Returns the service call to edit */
	public ServiceCall getServiceCall() {
		return this.serviceCall;
	}
	
	/** Sets the service call to edit */
	public void setServiceCall(ServiceCall serviceCall) {
		this.serviceCall = serviceCall;
	}
	
	/** Returns a list of customers */
	public List<Customer> getCustomerList() {
		return this.customerList;
	}
	
	/** Sets the list of customers */
	public void setCustomerList(List<Customer> customerList) {
		this.customerList = customerList;
	}

	/** Returns a list of operators */
	public List<Operator> getOperatorList() {
		return this.operatorList;
	}
	
	/** Sets the list of customers */
	public void setOperatorList(List<Operator> operatorList) {
		this.operatorList = operatorList;
	}
	
	/** Returns a status list */
	public List<Code> getStatusList() {
		return this.statusList;
	}
	
	/** Sets the status list */
	public void setStatusList(List<Code> statusList) {
		this.statusList = statusList;
	}
	
	/** Returns the priority codes list */
	public List<Code> getPriorityList() {
		return this.priorityList;
	}
	
	/** Sets the priority list */
	public void setPriorityList(List<Code> priorityList) {
		this.priorityList = priorityList;
	}
}